package com.lian.chatroom.config;

import com.lian.chatroom.protocol.Serializer;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 此类作用
 * 序列化方式有很多种，配置类可以灵活设置 选用哪种序列化方式，替代直接在 MessageCodecSharable协议类里修改
 */
public abstract class Config {

    static Properties properties;
    static {

        try {
            //加载本类下的资源文件
            InputStream inputStream = Config.class.getResourceAsStream("/application.properties");
            properties = new Properties();
            properties.load(inputStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

//    public static int getSetverPort(){
//        String value = properties.getProperty("server.port");
//        if (value == null){
//            return 8080;
//        }else {
//            return Integer.parseInt(value);
////            return Integer.valueOf(value);
//        }
//    }

    public static Serializer.Algorithm getSerializerAlgorithm(){
        String value = properties.getProperty("serializer.algorithm");
        if (value == null){
            return Serializer.Algorithm.java;
        }else {
            return Serializer.Algorithm.valueOf(value);
        }
    }

}
